<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul id="list">
        <li>1</li>
        <li>2</li>
    </ul>

    <script>
        var list = document.getElementById('list')
        list.addEventListener('click',function(){
            // alert('点击了ul')//点击子元素时，由于冒泡事件，也会触发父元素的监听
            if(event.target.tagName === 'LI'){
                alert(event.target.innerHTML)
            }
            else{
                alert("你点歪了")
            }
        })//将监听放在父标签中来执行，就是所谓的事件代理
    </script>
</body>
</html>